home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / DBL Pascal Library / LayerMgr / LayerMgr_Test ƒ / LayerMgr_Test.p next >
Text File  |  1993-02-15  |  2KB  |  97 lines

  1. program LayerMgr_Test;
  2.  
  3.     uses
  4.         Layers;
  5.  
  6.     type
  7. {Parameters to our LayerActionProc}
  8.         FindLayerParmRec = record
  9.                 findPSN: ^ProcessSerialNumber;
  10.                 foundLayer: LayerPtr;
  11.             end;
  12.         FindLayerParmPtr = ^FindLayerParmRec;
  13.  
  14. {FindLayerProcess: a LayerActionProc that looks for a specific PSN}
  15.     function FindLayerProcess (theWindow: WindowPtr; theLayer: LayerPtr; refCon: Longint): WindowActionCode;
  16.         var
  17.             code: WindowActionCode;
  18.             info: LayerInfoPtr;
  19.             p: FindLayerParmPtr;
  20.             err: OSErr;
  21.             same: Boolean;
  22.     begin
  23.     {Assume we'll be going to the next layer}
  24.         code := kNextLayer;
  25.     {If this window is really a layer, use it and go to the next "window"}
  26.         if IsLayer(theWindow) then
  27.             begin
  28.                 theLayer := theWindow;
  29.                 code := kNextWindow;
  30.             end;
  31.     {If we got a layer…}
  32.         if theLayer <> nil then
  33.             begin
  34.         {…with some info…}
  35.                 info := LayerInfoPtr(GetWRefCon(theLayer));
  36.                 if info <> nil then
  37.                     begin
  38.             {…see if the PSNs match}
  39.                         p := FindLayerParmPtr(refCon);
  40.                         err := SameProcess(info^.layerPSN, p^.findPSN^, same);
  41.                         if same then    {They match}
  42.                             begin
  43.                                 p^.foundLayer := theLayer;
  44.                                 code := kBreak;
  45.                             end;
  46.                     end;
  47.             end;
  48.         FindLayerProcess := code;
  49.     end;
  50.  
  51. {ProcessLayer: find a process' layer by its PSN}
  52.     function ProcessLayer (psn: ProcessSerialNumber): LayerPtr;
  53.         var
  54.             p: FindLayerParmRec;
  55.             code: WindowActionCode;
  56.     begin
  57.         p.findPSN := @psn;
  58.         p.foundLayer := nil;
  59.         code := ForEachLayerWindowDo(DeskLayer, LayerPtr(kAllLayers), LayerPtr(nil), @FindLayerProcess, Longint(@p));
  60.         ProcessLayer := p.foundLayer;
  61.     end;
  62.  
  63.     var
  64.         aPSN: ProcessSerialNumber;
  65.         err: OSErr;
  66.         aLayer: LayerPtr;
  67.         aWindow: WindowPtr;
  68.         aTitle: Str255;
  69.  
  70. begin
  71. {Test program walks through all the processes in the system. For each one found,}
  72. {print its layer’s name and visibility and the name and visibility of all its windows.}
  73.  
  74.     ShowText;
  75.     with aPSN do
  76.         begin
  77.             lowLongOfPSN := kNoProcess;
  78.             highLongOfPSN := kNoProcess;
  79.         end;
  80.     err := GetNextProcess(aPSN);
  81.     repeat
  82.         aLayer := ProcessLayer(aPSN);
  83.         if aLayer <> nil then
  84.             begin
  85.                 writeln(GetLayerName(aLayer), ' ', LayerVisible(aLayer));
  86.                 aWindow := LayerFrontWindow(aLayer);
  87.                 while aWindow <> nil do
  88.                     begin
  89.                         GetWTitle(aWindow, aTitle);
  90.                         writeln('   ', aTitle, ' ', WindowPeek(aWindow)^.visible);
  91.                         aWindow := WindowPtr(WindowPeek(aWindow)^.nextWindow);
  92.                     end;
  93.             end;
  94.         err := GetNextProcess(aPSN);
  95.     until err <> noErr;
  96.  
  97. end.